﻿#include "stdafx.h"
#include "AstBased.h"
#include "SiContext.h"
#include "ClassInstanceType.h"
#include "ClassContext.h"
#include "CodeGenerate/BlockGen.h"

void AstBased::draw(std::ostream & os) {
	dotLable(os, name + "{}");
	for (auto i : block) {
		dotPointTo(os, i);
	}
}

CodeGen * AstBased::makeGen(SiContext * parent)
{
	auto*p = expr->makeGen(parent);
	auto* x = dynamic_cast<ClassInstanceType*>(p->type);
	assert(x);

	auto *context = new ClassContext(parent, x);
	context->value = p;

	auto *a = new BlockGen();
	a->name = "base";
	for (auto i : block) {
		a->codes.push_back(
			i->makeGen(context)
		);
	}
	a->codes.push_back(p);	// 用来让块返回对象
	return a;
}
